package show.me.the.money.util.exp.standard;

import java.util.List;

import show.me.the.money.util.context.Context;
import show.me.the.money.util.exp.ExpRunner;
import show.me.the.money.util.exp.ExpSymbols;
import show.me.the.money.util.exp.Expression;

@SuppressWarnings("unchecked")
public class SUM extends Expression {
	public SUM() {
		symbol = ExpSymbols.SUM;
	}

	public Object run(List lsExp, Context ctx) {
		try {
			List la1 = (List)lsExp.get(1);
			double d1 = (Double)ExpRunner.run(la1, ctx);
			int size = lsExp.size();
			for (int i = 2; i < size; i++) {
				List la2 = (List)lsExp.get(i);
				double d2 = (Double)ExpRunner.run(la2, ctx);
				d1 += d2;
			}
			return String.valueOf(d1);
		} 
		catch (Exception e) {
			logger.error("run JSONException:", e);
		}
		return 0;
	}

}
